package com.ruibang.glass.equipment.controller;

import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.RepairPlanReq;
import com.ruibang.glass.equipment.entity.device.RepairPlan;
import com.ruibang.glass.equipment.entity.device.ScrapReport;
import com.ruibang.glass.equipment.service.RepairPlanService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import com.teaming.cloud.framework2.common.pojo.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * <p>
 *检维修计划
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/repair")
@Api(value = "检维修计划")
public class RepairPlanController {

    @Autowired
    private RepairPlanService repairPlanService;

    @GetMapping("getById/{id}")
    @ApiOperation(value = "根据Id查询检维修信息", response = ResultBody.class)
    public ResultBody getById(@PathVariable("id") String id) {
        return ResultBody.success(repairPlanService.getById(id));
    }

    @GetMapping("getDetail/{id}")
    @ApiOperation(value = "根据Id查询详情", response = ResultBody.class)
    public ResultBody getDetail(@PathVariable("id") String id) {
        return ResultBody.success(repairPlanService.getDetail(id));
    }


    @PostMapping("queryPage")
    @ApiOperation(value = "分页查询检维修信息", response = ResultBody.class)
    public ResultBody queryPage(@RequestBody PageRequest<RepairPlanReq> pageParam) {
        return ResultBody.success(repairPlanService.queryPage(pageParam));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "修改添加检维修信息", response = ResultBody.class)
    public ResultBody addOrUpdateCheck(@RequestBody RepairPlan repairPlan) {
        return ResultBody.success(repairPlanService.updateOrAdd(repairPlan));
    }

    @GetMapping("/deleteById/{id}")
    @ApiOperation(value = "通过ID删除检维修信息", notes = "通过ID删除检维修信息")
    public ResultBody delete(@PathVariable(value = "id") String id) {
        repairPlanService.lambdaUpdate().set(RepairPlan::getIsDelete, Constants.ONE_STR).eq(RepairPlan::getRepairId, id).update();
        return ResultBody.success();
    }

    @PostMapping("/batchDelete")
    @ApiOperation(value = "批量删除检维修信息", notes = "批量删除检维修信息")
    public ResultBody delete(@RequestBody List<String> ids) {
        repairPlanService.lambdaUpdate().set(RepairPlan::getIsDelete, Constants.ONE_STR).in(RepairPlan::getRepairId, ids).update();
        return ResultBody.success();
    }
}
